package com.ruoyi.community.controller.wxApi;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.community.domain.HouseHistory;
import com.ruoyi.community.service.IHouseHistoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 房屋记录Controller
 *
 * @author lj
 * @date 2022-02-22
 */
@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/wx/community/houseHistory")
@Api(tags = {"房屋记录"})
public class WxHouseHistoryController extends BaseController
{
    @Autowired
    private IHouseHistoryService houseHistoryService;

    /**
     * 查询房屋记录列表
     */
    @ApiOperation(value = "查询房屋记录列表")
    @GetMapping("/list")
    public TableDataInfo list(HouseHistory houseHistory)
    {
        startPage();
        List<HouseHistory> list = houseHistoryService.selectHouseHistoryList(houseHistory);
        if (ObjectUtils.isEmpty(list)){
            return getNoDataTable(list);
        }
        return getDataTable(list);
    }

    /**
     * 导出房屋记录列表
     */
    @ApiOperation(value = "导出房屋记录列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseHistory houseHistory)
    {
        List<HouseHistory> list = houseHistoryService.selectHouseHistoryList(houseHistory);
        ExcelUtil<HouseHistory> util = new ExcelUtil<HouseHistory>(HouseHistory.class);
        util.exportExcel(response, list, "房屋记录数据");
    }

    /**
     * 获取房屋记录详细信息
     */
    @ApiOperation(value = "获取房屋记录详细信息")
    @GetMapping(value = "/getInfo")
    public AjaxResult getInfo(Long id)
    {
        return AjaxResult.success(houseHistoryService.selectHouseHistoryById(id));
    }

    /**
     * 新增房屋记录
     */
    @ApiOperation(value = "新增房屋记录")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody HouseHistory houseHistory)
    {
        return toAjax(houseHistoryService.insertHouseHistory(houseHistory));
    }

    /**
     * 修改房屋记录
     */
    @ApiOperation(value = "修改房屋记录")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody HouseHistory houseHistory)
    {
        return toAjax(houseHistoryService.updateHouseHistory(houseHistory));
    }

    /**
     * 删除房屋记录
     */
    @ApiOperation(value = "删除房屋记录")
    @DeleteMapping("/remove/{id}")
    public AjaxResult remove(@PathVariable("id") Long id) {
        Long[] ids= {id};
        return toAjax(houseHistoryService.updateHouseHistoryByIds(ids));
    }
}
